
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GuestIDScreen.java
 *
 * Created on Dec 13, 2011, 8:59:46 PM
 */

/**
 *
 * @author dabeast23
 */
public class RoomService extends javax.swing.JFrame {

    /** Creates new form GuestIDScreen */
    public RoomService() {
        setResizable(false);
	setTitle("Hotel Kiosk: Room Service");
	setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        initComponents();
        this.setLocationRelativeTo(null);
        
    }
    
    public RoomService(ArrayList<Reservation> reservationList, Reservation currentGuest) {
        setResizable(false);
	setTitle("Hotel Kiosk: Room Service");
	setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        this.reservationList = reservationList;
        this.currentGuest = currentGuest;
        initComponents();
        hamburgerPrice=0;
        pizzaPrice=0;
        sandwichPrice=0;
        chickenPrice=0;
        totalCost=0;
        this.setLocationRelativeTo(null);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundPanel = new javax.swing.JPanel();
        backButton = new javax.swing.JButton();
        roomServiceLabel = new javax.swing.JLabel();
        orderButton = new javax.swing.JButton();
        roomServiceLabel1 = new javax.swing.JLabel();
        roomServiceLabel2 = new javax.swing.JLabel();
        roomServiceLabel4 = new javax.swing.JLabel();
        chickenTextField = new javax.swing.JTextField();
        hamburgerTextField = new javax.swing.JTextField();
        pizzaTextField = new javax.swing.JTextField();
        sandwichTextField = new javax.swing.JTextField();
        roomServiceLabel5 = new javax.swing.JLabel();
        priceLabel = new javax.swing.JLabel();
        roomServiceLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        backgroundPanel.setBackground(new java.awt.Color(102, 0, 0));
        backgroundPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        backButton.setBackground(new java.awt.Color(255, 255, 204));
        backButton.setFont(new java.awt.Font("Comic Sans MS", 0, 11));
        backButton.setForeground(new java.awt.Color(255, 255, 255));
        backButton.setText("Back");
        backButton.setContentAreaFilled(false);
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });
        backgroundPanel.add(backButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 270, -1, -1));

        roomServiceLabel.setFont(new java.awt.Font("Tahoma", 1, 24));
        roomServiceLabel.setForeground(new java.awt.Color(255, 255, 204));
        roomServiceLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        roomServiceLabel.setText("Order Room Service");
        backgroundPanel.add(roomServiceLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 0, 330, 50));

        orderButton.setBackground(new java.awt.Color(255, 255, 204));
        orderButton.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N
        orderButton.setForeground(new java.awt.Color(102, 0, 0));
        orderButton.setText("Place Order");
        orderButton.setBorder(null);
        orderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderButtonActionPerformed(evt);
            }
        });
        backgroundPanel.add(orderButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 260, 171, 33));
        orderButton.setVisible(false);

        roomServiceLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        roomServiceLabel1.setForeground(new java.awt.Color(255, 255, 204));
        roomServiceLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        roomServiceLabel1.setText("Turkey Sandwich.....$4.50");
        backgroundPanel.add(roomServiceLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 130, 200, 50));

        roomServiceLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
        roomServiceLabel2.setForeground(new java.awt.Color(255, 255, 204));
        roomServiceLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        roomServiceLabel2.setText("6 Piece Chicken Fingers.....$6.75");
        backgroundPanel.add(roomServiceLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 170, 240, 50));

        roomServiceLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        roomServiceLabel4.setForeground(new java.awt.Color(255, 255, 204));
        roomServiceLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        roomServiceLabel4.setText("Total Cost:");
        backgroundPanel.add(roomServiceLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 210, 180, 50));

        chickenTextField.setText("0");
        chickenTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                chickenTextFieldKeyReleased(evt);
            }
        });
        backgroundPanel.add(chickenTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 180, 40, 30));

        hamburgerTextField.setText("0");
        hamburgerTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hamburgerTextFieldActionPerformed(evt);
            }
        });
        hamburgerTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                hamburgerTextFieldKeyReleased(evt);
            }
        });
        backgroundPanel.add(hamburgerTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 60, 40, 30));

        pizzaTextField.setText("0");
        pizzaTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                pizzaTextFieldKeyReleased(evt);
            }
        });
        backgroundPanel.add(pizzaTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 100, 40, 30));

        sandwichTextField.setText("0");
        sandwichTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                sandwichTextFieldKeyReleased(evt);
            }
        });
        backgroundPanel.add(sandwichTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 140, 40, 30));

        roomServiceLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        roomServiceLabel5.setForeground(new java.awt.Color(255, 255, 204));
        roomServiceLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        roomServiceLabel5.setText("Hamburger.....$5.99");
        backgroundPanel.add(roomServiceLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 50, 180, 50));

        priceLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        priceLabel.setForeground(new java.awt.Color(255, 255, 204));
        priceLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        priceLabel.setText("$0.00");
        backgroundPanel.add(priceLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 210, 160, 50));

        roomServiceLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
        roomServiceLabel6.setForeground(new java.awt.Color(255, 255, 204));
        roomServiceLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        roomServiceLabel6.setText("Pizza (1 slice).....$2.00");
        backgroundPanel.add(roomServiceLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 90, 180, 50));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        CurrentGuest CG = new CurrentGuest(reservationList,currentGuest);
        CG.setVisible(true);
        this.setVisible(false);
}//GEN-LAST:event_backButtonActionPerformed

    public boolean isNumber(String numString)
    {
        try
        {
            Double.parseDouble(numString);
        }
        catch (NumberFormatException nfe)
        {
            return false;
        }
        return true;
    }

    private void updatePriceField()
    {
        totalCost=0;
        totalCost = hamburgerPrice + pizzaPrice + sandwichPrice+chickenPrice;

        priceLabel.setText("$"+(double)Math.round(totalCost * 100) / 100);
    }
    private void orderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderButtonActionPerformed
        // TODO add your handling code here:
        String orderReview="";
        if(hamburgerPrice!=0)
        {
            orderReview = orderReview + "Hamburgers: " +  hamburgerTextField.getText()+ "\n";
        }
        if(pizzaPrice!=0)
        {
            orderReview = orderReview + "Slices of pizza: " +  pizzaTextField.getText()+ "\n";
        }
        if(sandwichPrice!=0)
        {
            orderReview = orderReview + "Turkey sandwiches: " +  sandwichTextField.getText()+ "\n";
        }
        if(chickenPrice!=0)
        {
            orderReview = orderReview + "6 piece chicken fingers: " +  chickenTextField.getText()+ "\n";
        }

        int n = JOptionPane.showConfirmDialog(this,
            "Review Order: \n"+orderReview+"\nAre you sure you want to add "+"$"+(double)Math.round(totalCost * 100) / 100+" to your total bill?",
            "Confirm Purchase", JOptionPane.YES_NO_OPTION);

        if(n==0)
        {
            JOptionPane.showMessageDialog(this,
    "$"+(double)Math.round(totalCost * 100) / 100 +" has been added to your total bill!");
            currentGuest.updateTotalBill((double)Math.round(totalCost * 100) / 100);
            CurrentGuest CG = new CurrentGuest(reservationList,currentGuest);
            CG.setVisible(true);
            this.setVisible(false);
        }
    }//GEN-LAST:event_orderButtonActionPerformed

    private void hamburgerTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hamburgerTextFieldActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_hamburgerTextFieldActionPerformed

    private void hamburgerTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_hamburgerTextFieldKeyReleased
        // TODO add your handling code here:
        String numOfItems = hamburgerTextField.getText();
      if(numOfItems.equals("")|| numOfItems.equals("0"))
      {
          //hamburgerTextField.setText("0");
          hamburgerPrice = 0;
          updatePriceField();
      }
      if((numOfItems.equals("") || numOfItems.equals("0"))  && (pizzaTextField.getText().equals("")||pizzaTextField.getText().equals("0"))&& (sandwichTextField.getText().equals("")||sandwichTextField.getText().equals("0"))&& (chickenTextField.getText().equals("")||chickenTextField.getText().equals("0")))
      {
          orderButton.setVisible(false);
      }
      if(isNumber(numOfItems)==true)
      {
          orderButton.setVisible(true);
          hamburgerPrice = (5.99 * Double.parseDouble(numOfItems));
          updatePriceField();
      }
    }//GEN-LAST:event_hamburgerTextFieldKeyReleased

    private void pizzaTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pizzaTextFieldKeyReleased
        // TODO add your handling code here:
        String numOfItems = pizzaTextField.getText();
        if(numOfItems.equals("")|| numOfItems.equals("0"))
      {
          //pizzaTextField.setText("0");
          pizzaPrice = 0;
          updatePriceField();
      }
        if((numOfItems.equals("") || numOfItems.equals("0"))  && (hamburgerTextField.getText().equals("")||hamburgerTextField.getText().equals("0"))&& (sandwichTextField.getText().equals("")||sandwichTextField.getText().equals("0"))&& (chickenTextField.getText().equals("")||chickenTextField.getText().equals("0")))
      {
          orderButton.setVisible(false);
      }
        if(isNumber(numOfItems)==true)
      {
            orderButton.setVisible(true);
          pizzaPrice = (2.00 * Double.parseDouble(numOfItems));
          updatePriceField();
      }
    }//GEN-LAST:event_pizzaTextFieldKeyReleased

    private void sandwichTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sandwichTextFieldKeyReleased
        // TODO add your handling code here:
        String numOfItems = sandwichTextField.getText();
      if(numOfItems.equals("")|| numOfItems.equals("0"))
      {
          //sandwichTextField.setText("0");
          sandwichPrice = 0;
          updatePriceField();
      }

        if((numOfItems.equals("") || numOfItems.equals("0"))  && (pizzaTextField.getText().equals("")||pizzaTextField.getText().equals("0"))&& (hamburgerTextField.getText().equals("")||hamburgerTextField.getText().equals("0"))&& (chickenTextField.getText().equals("")||chickenTextField.getText().equals("0")))
      {
          orderButton.setVisible(false);
      }
      if(isNumber(numOfItems)==true)
      {
          orderButton.setVisible(true);
          sandwichPrice = (4.50 * Double.parseDouble(numOfItems));
          updatePriceField();
      }
    }//GEN-LAST:event_sandwichTextFieldKeyReleased

    private void chickenTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_chickenTextFieldKeyReleased
        // TODO add your handling code here:
        String numOfItems = chickenTextField.getText();

      if(numOfItems.equals("")|| numOfItems.equals("0"))
      {
          //chickenTextField.setText("0");
          chickenPrice = 0;
          updatePriceField();
      }

        if((numOfItems.equals("") || numOfItems.equals("0"))  && (pizzaTextField.getText().equals("")||pizzaTextField.getText().equals("0"))&& (sandwichTextField.getText().equals("")||sandwichTextField.getText().equals("0"))&& (hamburgerTextField.getText().equals("")||hamburgerTextField.getText().equals("0")))
      {
          orderButton.setVisible(false);
      }
      if(isNumber(numOfItems)==true)
      {
          orderButton.setVisible(true);
          chickenPrice = (6.75 * Double.parseDouble(numOfItems));
          updatePriceField();
      }
    }//GEN-LAST:event_chickenTextFieldKeyReleased

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GuestIDScreen().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JPanel backgroundPanel;
    private javax.swing.JTextField chickenTextField;
    private javax.swing.JTextField hamburgerTextField;
    private javax.swing.JButton orderButton;
    private javax.swing.JTextField pizzaTextField;
    private javax.swing.JLabel priceLabel;
    private javax.swing.JLabel roomServiceLabel;
    private javax.swing.JLabel roomServiceLabel1;
    private javax.swing.JLabel roomServiceLabel2;
    private javax.swing.JLabel roomServiceLabel4;
    private javax.swing.JLabel roomServiceLabel5;
    private javax.swing.JLabel roomServiceLabel6;
    private javax.swing.JTextField sandwichTextField;
    // End of variables declaration//GEN-END:variables
    public ArrayList<String> userIDs = new ArrayList();
    private ArrayList <Reservation> reservationList;
    Reservation currentGuest;

    private double totalCost;
    private double hamburgerPrice;
    private double pizzaPrice;
    private double sandwichPrice;
    private double chickenPrice;

    
}
